import java.io.IOException;

public class Serializer {
    public static void main(String[] args) throws IOException {}

    public static int[] serialize_int(int n){
        int[] res = new int[1];
        res[0] = n;
        return res;
    }

    public static int[] serialize_long(long n){
        int[] res = new int[2];
        res[0] = (int) (n >> 32);
        res[1] = (int) (n & 0xFFFFFFFFL);
        return res;
    }

    public static int[] serialize_double(double d){
        return serialize_long(Double.doubleToRawLongBits(d));
    }

    public static int[] serialize_string(String s) {
        int val_len;

        if (s.length() <= 253) {
            val_len = 1 + s.length();
        } else {
            val_len = 4 + s.length();
        }
        while (val_len % 4 != 0) val_len++;
        char[] b_val = new char[val_len];

        if (s.length() <= 253) {
            b_val[0] = (char) s.length();
            for (char i = 0; i < s.length(); i++) {
                b_val[i + 1] = s.charAt(i);
            }
        } else {
            b_val[0] = (char) 254;
            b_val[1] = (char) ((s.length() & 0x00FF0000) >> 16);
            b_val[2] = (char) ((s.length() & 0x0000FF00) >> 8);
            b_val[3] = (char)  (s.length() & 0x000000FF);

            for (int i = 0; i < s.length(); i++) {
                b_val[i + 4] = s.charAt(i);
            }
        }

        int[] val = new int[val_len / 4];
        for (int i = 0; i < val_len / 4; i++) {
            val[i] = b_val[i * 4 + 3] + (((int) b_val[i * 4 + 2]) << 8) +
                                        (((int) b_val[i * 4 + 1]) << 16) +
                                        (((int) b_val[i * 4]) << 24);
        }

        return val;
    }
}
